<div class="site-dir"><?php
    echo $this->Html->link('Trang chủ', array('controller' => 'index', 'action' => 'index'));
    echo ' >> '.$this->Html->link('PTCS', array('controller' => 'subjects', 'action' => 'index'));
    if(isset($gradeId)) {
        foreach($gradeView as $grade) {
            if($grade['Grade']['id'] == $gradeId) {
                $gradeName = $grade['Grade']['name'];
            }
        }
        echo ' >> '.$this->Html->link($subjectView['Subject']['name'], array('controller' => 'subjects', 'action' => 'view', $subjectView['Subject']['id']));
        echo ' >> '.$gradeName;
    } else {
        echo ' >> '.$subjectView['Subject']['name'];
    }
    
?></div>
<div class="subject-box">
    <div class="subject-box-header">
        <div class="subject-name">
            <?php echo $this->Html->link($this->Html->image(subject_img($subjectView['Subject']['id'])), array('controller' => 'subjects', 'action' => 'view', $subjectView['Subject']['id']), array('escape' => false));?>
        </div>
        <div class="test-total"><?php
            echo $totalTest.' đề';
        ?></div>
        <div class="subject-sort">
            <p>Lọc theo<?php
                if($subjectView['Subject']['id'] == 3) {
                    foreach($gradeView as $grade) {
                        if($grade['Grade']['id'] != 6 && $grade['Grade']['id'] != 7) {
                            echo ' :: '.$this->Html->link($grade['Grade']['name'], array('controller' => 'subjects', 'action' => 'view', $subjectView['Subject']['id'], $grade['Grade']['id']));
                        }
                    }
                } else {
                    foreach($gradeView as $grade) {
                        echo ' :: '.$this->Html->link($grade['Grade']['name'], array('controller' => 'subjects', 'action' => 'view', $subjectView['Subject']['id'], $grade['Grade']['id']));
                    }
                }
            ?>
            </p>
            <hr />
            <p>
                Sắp xếp theo ::: <?php echo $this->Paginator->sort('grade_id', 'Khối lớp');?>
                ::: <?php echo $this->Paginator->sort('like', 'Ưa thích');?>
                ::: <?php echo $this->Paginator->sort('user_id', 'Tên người tạo');?>
            </p>
        </div>
    </div>
<?php if($testView) {?>
    <div class="subject-box-footer">
    <?php
        $i = 1;
        foreach($testView as $test) {     
    ?>
        <div class="subject-row">
            <div class="test-id">
                <?php echo $this->Html->link($test['Test']['id'], array('controller' => 'tests', 'action' => 'view', $test['Test']['id']));?>
            </div>
            <div class="subject-test-detail">
                <p><?php
                    echo $this->Html->link($test['Test']['name'], array('controller' => 'tests', 'action' => 'view', $test['Test']['id']));
                    echo $this->Html->image(grade_img($subjectView['Subject']['id'], $test['Grade']['id']));
                ?></p>
                <p class="detail">
                    <span class="like"><?php echo $test['Test']['like'];?></span> <?php echo $this->Html->image('thumbs-up.gif', array('align' => 'middle'));?> <span class="dislike"><?php echo $test['Test']['dislike'];?></span> <?php echo $this->Html->image('thumbs-down.gif', array('align' => 'middle'));?> ----
                    <?php echo $test['Test']['question_updated'];?> câu,
                    <?php echo $test['Test']['normal_updated'];?> tự luận --
                    Gửi lúc <?php echo $this->Time->format('G:i d/m/Y', $test['Test']['created']);?> --
                    <?php if($test['User']['role'] == 'admin') {?>
                    Của hệ thống
                    <?php } else {?>
                    Của <?php echo $this->Html->link($test['User']['username'], array('controller' => 'users', 'action' => 'view', $test['User']['id'])); }?>
                </p>
            </div>
        </div><!-- end row --!>
    <?php $i++;}?>
    </div><!-- end subject-box-footer --!>
<?php } else {?>
    <div class="subject-box-footer">
        <center>Không có đề</center>
    </div>
<?php }?>
    <div class="paging">
        <?php
            echo $this->Paginator->first('Trang đầu');
            echo $this->Paginator->numbers(array('separator' => ''));
            echo $this->Paginator->last('Trang cuối');
        ?>
    </div>
</div>
<?php
function grade_img($subjectId, $gradeId) {
    if($subjectId == 1) {
        return 'subjects/ToanHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 2) {
        return 'subjects/VatLy/'.$gradeId.'.gif';
    }
    if($subjectId == 3) {
        return 'subjects/HoaHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 4) {
        return 'subjects/SinhHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 5) {
        return 'subjects/NguVan/'.$gradeId.'.gif';
    }
    if($subjectId == 6) {
        return 'subjects/LichSu/'.$gradeId.'.gif';
    }
    if($subjectId == 7) {
        return 'subjects/DiaLy/'.$gradeId.'.gif';
    }
    if($subjectId == 8) {
        return 'subjects/TiengAnh/'.$gradeId.'.gif';
    }
    if($subjectId == 9) {
        return 'subjects/TinHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 10) {
        return 'subjects/CongNghe/'.$gradeId.'.gif';
    }
    if($subjectId == 11) {
        return 'subjects/Khac/'.$gradeId.'.gif';
    }
}
function subject_img($subjectId) {
    if($subjectId == 1) {
        return 'subjects/toan-hoc.gif';
    }
    if($subjectId == 2) {
        return 'subjects/vat-ly.gif';
    }
    if($subjectId == 3) {
        return 'subjects/hoa-hoc.gif';
    }
    if($subjectId == 4) {
        return 'subjects/sinh-hoc.gif';
    }
    if($subjectId == 5) {
        return 'subjects/ngu-van.gif';
    }
    if($subjectId == 6) {
        return 'subjects/lich-su.gif';
    }
    if($subjectId == 7) {
        return 'subjects/dia-ly.gif';
    }
    if($subjectId == 8) {
        return 'subjects/tieng-anh.gif';
    }
    if($subjectId == 9) {
        return 'subjects/tin-hoc.gif';
    }
    if($subjectId == 10) {
        return 'subjects/cong-nghe.gif';
    }
    if($subjectId == 11) {
        return 'subjects/khac.gif';
    }
}
?>